package com.ruoyi.spm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.spm.domain.Spj;
import com.ruoyi.spm.service.ISpjService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应关系数据管理Controller
 * 
 * @author wangxinyu
 * @date 2025-05-23
 */
@RestController
@RequestMapping("/spm/spj")
public class SpjController extends BaseController
{
    @Autowired
    private ISpjService spjService;

    /**
     * 查询供应关系数据管理列表
     */
    @PreAuthorize("@ss.hasPermi('spm:spj:list')")
    @GetMapping("/list")
    public TableDataInfo list(Spj spj)
    {
        startPage();
        List<Spj> list = spjService.selectSpjList(spj);
        return getDataTable(list);
    }

    /**
     * 导出供应关系数据管理列表
     */
    @PreAuthorize("@ss.hasPermi('spm:spj:export')")
    @Log(title = "供应关系数据管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Spj spj)
    {
        List<Spj> list = spjService.selectSpjList(spj);
        ExcelUtil<Spj> util = new ExcelUtil<Spj>(Spj.class);
        util.exportExcel(response, list, "供应关系数据管理数据");
    }

    /**
     * 获取供应关系数据管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('spm:spj:query')")
    @GetMapping(value = "/{sno}")
    public AjaxResult getInfo(@PathVariable("sno") String sno)
    {
        return success(spjService.selectSpjBySno(sno));
    }

    /**
     * 新增供应关系数据管理
     */
    @PreAuthorize("@ss.hasPermi('spm:spj:add')")
    @Log(title = "供应关系数据管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Spj spj)
    {
        return toAjax(spjService.insertSpj(spj));
    }

    /**
     * 修改供应关系数据管理
     */
    @PreAuthorize("@ss.hasPermi('spm:spj:edit')")
    @Log(title = "供应关系数据管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Spj spj)
    {
        return toAjax(spjService.updateSpj(spj));
    }

    /**
     * 删除供应关系数据管理
     */
    @PreAuthorize("@ss.hasPermi('spm:spj:remove')")
    @Log(title = "供应关系数据管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{snos}")
    public AjaxResult remove(@PathVariable String[] snos)
    {
        return toAjax(spjService.deleteSpjBySnos(snos));
    }
}
